package com.atguigu.graph;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;

public class BFS {
    public static void Bfs(Node node){
        if(node==null) return;
        Queue<Node> queue=new LinkedList<>();
        Set<Node> set=new HashSet<>();
        queue.add(node);
        set.add(node);
        while(!queue.isEmpty()){
            Node poll = queue.poll();
            System.out.println(poll.val);
            for(Node cur: poll.nexts){
                if(!set.contains(cur)){
                    set.add(cur);
                    queue.add(cur);
                }
            }
        }
    }
}
